package com.scs.application.modules.adm.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.adm.entity.MatrAuditItem;
import com.scs.application.modules.adm.service.MatrAuditItemService;
import com.scs.application.modules.sys.model.PageResult;
import com.scs.application.modules.sys.model.RestResult;
import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 耗材准入汇总单明细 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/adm/matr_audit_item")
public class MatrAuditItemController extends CrudController<MatrAuditItemService, MatrAuditItem>{
    /**
    * @Description： 添加准入单据
    */
    @PostMapping("/saveBatch")
    public RestResult saveBatch(@Valid @RequestBody List<MatrAuditItem> entityList) {
        service.saveBatch(entityList);
        return RestResult.ok("批量添加成功",  entityList);
    }

    /**
     * @Description： 耗材准入汇总单明细视图-关联申请耗材明细
     */
    @GetMapping("/pageForAuditSelectWitchMatr")
    public RestResult pageForAuditSelectWitchMatr(@RequestParam Map<String, Object> reqData){
        QueryContext queryContext = QueryContextHolder.currentContext();
        Map<String, Object> userParam =null;
        //固定参数
        if(reqData.containsKey("userParam")){
            JSONObject ob = JSON.parseObject(reqData.get("userParam")+"");
            userParam= Maps.newHashMap(ob);
        }

        IPage pageResult = service.pageForAuditSelectWitchMatr(queryContext,userParam);
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }



    /**
     * @Description： 耗材准入汇总单明细视图-关联申请耗材明细-以及报价明细
     */
    @GetMapping("/pageForAuditSelectWitchMatrAndResult")
    public RestResult pageForAuditSelectWitchMatrAndResult(@RequestParam Map<String, Object> reqData){
        QueryContext queryContext = QueryContextHolder.currentContext();
        Map<String, Object> userParam =null;
        //固定参数
        if(reqData.containsKey("userParam")){
            JSONObject ob = JSON.parseObject(reqData.get("userParam")+"");
            userParam= Maps.newHashMap(ob);
        }

        IPage pageResult = service.pageForAuditSelectWitchMatrAndResult(queryContext,userParam);
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }
}
